<?php
/**
 * Created by PhpStorm.
 * User: Gooraye
 * Date: 2015/12/18
 * Time: 9:46
 */

namespace Test\Controller;

class TestUmengController extends TestController
{

    function _initialize()
    {
        parent::_initialize();
        vendor('UmengPushApi',APP_PATH.'Api/Vendor/Umeng/');
    }

    protected $Android_appkey = '56fc95a767e58e12fe00131b';
    protected $Android_secret = 'a9tpfhwc6ssbqoxubyxxndxalncgvjlb';

    protected $IOS_appkey = '56de24f9e0f55a5d8a001e4c';
    protected $IOS_secret = 'blbr4vxs2wkfasjfmgcsduves8gbtedc';

    public function index(){
        $this->display();
        //$this->sendAndroidUnicast();
        //$this->sendAndroidBroadcast();
        //$this->sendIOSUnicast();
        //$this->sendIOSBroadcast();

    }


    public function Android(){
        if(IS_POST){
            $entity = I('post.');
            $entity['alias_type']='sunsun';
            $UmengAndroid = new \UmengPushApi($entity['appkey'],$entity['secret']);
            $type = $entity['push_type'];
            unset($entity['appkey'],$entity['secret'],$entity['push_type']);
            dump($entity);
            if( $type==1){
                $result = $UmengAndroid->sendAndroidBroadcast($entity);
                dump($result);
            }
            if( $type==2){
                $result = $UmengAndroid->sendAndroidCustomizedcast($entity);
                dump($result);
            }
        }
        $this->display();

    }

    public function IOS(){
        if(IS_POST){
            $entity = I('post.');
            $entity['alias_type']='sunsun';
            $UmengIOS = new \UmengPushApi($entity['appkey'],$entity['secret']);
            $type = $entity['push_type'];
            unset($entity['appkey'],$entity['secret'],$entity['push_type']);
            $entity['badge']=0;
            $entity['sound']='chime';
            dump($entity);
            if( $type==1){
                $UmengIOS->sendIOSBroadcast($entity);
            }
            if( $type==2){
                $UmengIOS->sendIOSCustomizedcast($entity);
            }
        }
        $this->display();
    }

    private function sendAndroidCustomizedcast(){
        $UmengAndroid = new \UmengPushApi($this->Android_appkey,$this->Android_secret);

        $entity = array(
            'alias'=>18,
            'alias_type'=>'sunsun',
            'ticker'=>'测试单播提示文字',
            'title'=>'测试单播标题',
            'text'=>'测试单播文字描述',
            'after_open'=>'go_url',
            'url'=>'https://www.baidu.com',
            'production_mode'=>'false'

        );
        header('content-type:text/html;charset=utf-8');
        dump($entity);
        $result = $UmengAndroid->sendAndroidCustomizedcast($entity);
        dump($result);

    }

    private function sendAndroidUnicast(){
        $UmengAndroid = new \UmengPushApi($this->Android_appkey,$this->Android_secret);

        $entity = array(
            'device_tokens'=>'AjJUusw_AU3m1gNnqzWoQq-fAckB8yJjw-1zdCA0sJDL',
            'ticker'=>'测试单播提示文字',
            'title'=>'测试单播标题',
            'text'=>'测试单播文字描述',
            'after_open'=>'go_url',
            'url'=>'https://www.baidu.com',
            'production_mode'=>'false'

        );
        $UmengAndroid->sendAndroidUnicast($entity);
    }

    private function sendAndroidBroadcast(){
        $UmengAndroid = new \UmengPushApi($this->Android_appkey,$this->Android_secret);

        $entity = array(
            'ticker'=>'测试广播提示文字',
            'title'=>'测试广播标题',
            'text'=>'测试广播文字描述',
            'after_open'=>'go_url',
            'url'=>'https://www.baidu.com',
            'production_mode'=>'false'

        );
        $UmengAndroid->sendAndroidBroadcast($entity);
    }

    private function sendIOSUnicast(){
        $UmengIOS = new \UmengPushApi($this->IOS_appkey,$this->IOS_secret);

        $entity = array(
            'device_tokens'=>'996974cc8f24bd1b239c8369347085d3be30df452d91819420ec57e685dbe21c',
            'alert'=>'IOS 单播测试',
            'badge'=>0,
            'sound'=>'chime',
            'production_mode'=>'false'

        );
        $UmengIOS->sendIOSUnicast($entity);
    }

    private function sendIOSBroadcast(){
        $UmengUmengIOS = new \UmengPushApi($this->IOS_appkey,$this->IOS_secret);

        $entity = array(
            'alert'=>'IOS 广播测试',
            'badge'=>0,
            'sound'=>'chime',
            'production_mode'=>'false'

        );
        $UmengUmengIOS->sendIOSBroadcast($entity);
    }



}